package T;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

public class Stream4 {

    private List<Person> list= new ArrayList<>();

    public static void main(String[] args) {
        new Stream4().test();
    }

    public void test() {
        Person person1 = new Person("筛选默认值", 22, 1);
        Person person2 = new Person("默认2", 2, 2);
        Person person3 = new Person("默认3", 3, 3);
        list.add(person1);
        list.add(person2);
        list.add(person3);

        /**
         * 包含“设计模式”，按照(年龄)排序 的(并行流)
         */
        List<Person> collect = list.parallelStream().filter(person -> person.getName().contains("默认"))
                .sorted(Comparator.comparing(Person::getAge))
                .limit(3)
                .collect(Collectors.toList());
        System.out.println(collect);
    }
}
